package org.uninova.mobis.utils;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;

public class DBUtilsImpl {

	public DBUtilsImpl() {}
	
	public Connection startConnection(String url, String username, String password) {
		//String username = "paf" ;
		//String password = "grisgris123" ;
		//String url = "jdbc:sqlserver://localhost:1433;databaseName=MobiSDB" ;
		
		try {
			Class.forName("com.mysql.jdbc.Driver");
			//Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
			Connection conn = DriverManager.getConnection(url, username, password);
			
			return conn ;
			
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null ;
	}
	
	public ResultSet queryDB(Connection conn, String sqlQuery) {
		try {	
			ResultSet set = conn.createStatement().executeQuery(sqlQuery) ;
			
			return set ;
			
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null ;
	}
	
	public int modifyDB(Connection conn, String sqlStatement) {
		try {
			return conn.createStatement().executeUpdate(sqlStatement) ;
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return -1 ;
	}

}
